package com.fhd.service.Manager;

import com.fhd.dao.BaseDao;
import com.fhd.dao.Manager.ManagerDao;
import com.fhd.dao.Manager.ManagerDaoImplement;
import com.fhd.pojo.Manager;

import java.sql.Connection;
import java.util.Objects;

public class ManagerServiceImplement implements ManagerService{
    // 业务层调用Dao层
    private ManagerDao managerDao = null;
    public ManagerServiceImplement() {
        managerDao = new ManagerDaoImplement();
    }

    // 管理端登录
    @Override
    public Manager login(String userCode, String userPassword) {
        Connection conn = null;
        Manager manager = null;
        try {
            // 获取连接，
            conn = BaseDao.getConnection();
            manager = managerDao.getLoginManager(conn,userCode);

            //判断找到的管理端不为空的前提下密码是否对
            if (manager != null) {
                if (!Objects.equals(manager.getUserPassword(),userPassword)) {
                    manager = null;
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            BaseDao.close(conn,null,null);
        }
        return manager;
    }
}
